package com.contory.ssn_lgnd.app.title;

import com.contory.ssn_lgnd.app.Assets;
import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.app.comp.ViewObject;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;
import com.contory.ssn_lgnd.framework.gl.TextureRegion;
import com.contory.ssn_lgnd.framework.math.Rectangle;

public class TitlePlayerObject extends ViewObject implements DrawPtr, UpdatePtr{
	static float minV;
	static float maxV;
	static float minH;
	static float maxH;
	
	static float incVel = 0.015f;
	static float hVel;
	byte incDir = -1;
	
	TextureRegion trCopy;
	
	static final byte idle = 0;
	static final byte down = 1;
	static final byte end = 2;
	byte state = 0;
	
	boolean bool_start = false;
	boolean bool_downEnd = false;
	
	public TitlePlayerObject(){
		setXY_WH_TR(10, 4.5f, 1, 0.5f, Assets.tex_reg_player);
		trCopy = tr.copy();
		float len = trCopy.v2 - trCopy.v1;
		minV = trCopy.v1 + len * 0.5f;
		maxV = trCopy.v1 + len * 0.8f;
		
		minH = h * 0.5f;
		maxH = h * 0.8f;
		
		hVel = h * incVel / len;
		
		trCopy.v2 = trCopy.v1 + len * 0.6f;
		h = h * 0.6f;
	}
	
	@Override
	public void draw(SpriteBatcher batcher) {
		batcher.drawSprite(x, y, w, h, trCopy);
	}
	
	public void setStart(){
		bool_start = true;
	}
	
	public boolean isDownEnd(){
		return bool_downEnd;
	}
	
	@Override
	public void update(float deltaTime) {
		switch(state){
			case idle:
				if(incDir == -1){
					if(!bool_start){
						trCopy.v2 -= deltaTime * incVel;
						h -= deltaTime * hVel;
						if(trCopy.v2 < minV){
							trCopy.v2 = minV;
							h = minH;
							incDir = 1;
						}
					}
					else{
						state = down;
					}
				}
				else if(incDir == 1){
					trCopy.v2 += deltaTime * incVel;
					h += deltaTime * hVel;
					if(trCopy.v2 > maxV){
						trCopy.v2 = maxV;
						h = maxH;
						incDir = -1;
					}
				}
			break;
			
			case down:
				trCopy.v2 -= deltaTime * incVel;
				h -= deltaTime * hVel;
				if(trCopy.v2 < trCopy.v1){
					trCopy.v2 = trCopy.v1;
					h = 0;
					state = end;
					bool_downEnd = true;
				}
			break;
			
			case end:
			break;
		}
	}
}
